﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;

namespace Fabrication.ValueProviders
{
    internal sealed class GenericCollectionProvider : IValueProvider
    {
        private static readonly Type collectionType = typeof(Collection<>);
        private Type genericCollectionType;

        public void Initialize(PropertyInfo property)
        {
            var itemType = property.PropertyType.GetGenericArguments().Single();
            genericCollectionType = collectionType.MakeGenericType(itemType);
        }

        object IValueProvider.GetValue(object item)
        {
            return Activator.CreateInstance(genericCollectionType);
        }
    }
}